package com.demo;

import com.wanghaicheng.util.PdfUtil;
import com.wanghaicheng.util.WordUtil;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.docx4j.openpackaging.exceptions.Docx4JException;


import java.io.FileOutputStream;
import java.io.IOException;

public class PdfDemo {
    public static void main(String[] args) {
        try {
            String docxPath = "D:\\code\\office-tool\\file\\通知单.docx";
            String pdfPath = "D:\\code\\office-tool\\file\\通知单.pdf";
            String newDocxPath = "D:\\code\\office-tool\\file\\通知单1.docx";
            XWPFDocument document = WordUtil.loadDocumentFromFile(docxPath);
            WordUtil.replacePlaceholder(document, "${unit}", "张三");
            WordUtil.replacePlaceholder(document, "${number}", "编号1111");
            document.write(new FileOutputStream(newDocxPath));
            PdfUtil.convert(newDocxPath, pdfPath);
        } catch (Docx4JException | IOException e) {
            e.printStackTrace();
        }
    }
}
